package com.qf.listener;


import com.qf.pojo.TbGoodsType;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/17 10:36
 */
@WebListener
public class GoodsTypeContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        GoodsTypeService goodsService=new GoodsTypeServiceImpl();
        List<TbGoodsType> goodsTypeList=goodsService.find();
        ServletContext servletContext = servletContextEvent.getServletContext();
//        System.out.println("goodsTypeList = " + goodsTypeList);
        servletContext.setAttribute("goodsTypeList", goodsTypeList);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        servletContextEvent.getServletContext().removeAttribute("goodsType");
    }
}
